<%--
  Created by IntelliJ IDEA.
  User: sunhao
  Date: 2015/9/30 0030
  Time: 下午 2:03
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE HTML>

<html>
<head>
  <title>工资列表</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <%--<link href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">--%>
  <link href="/static/bui/css/bs3/dpl.css" rel="stylesheet" type="text/css"/>
  <link href="/static/bui/css/bs3/bui.css" rel="stylesheet" type="text/css"/>
</head>
<body>

<div class="doc-content">
  <div class="panel">
    <div class="panel-header">
      <h3>工资列表</h3>
    </div>

      <div class="row">
        <div class="span21 offset3 control-row-auto">
          <div id="grid"></div>
          <input type="hidden" name="lesson">
        </div>
      </div>

      <script type="text/javascript" src="/static/bui/js/jquery-1.8.1.min.js"></script>
      <script type="text/javascript" src="/static/bui/js/bui.js"></script>
      <script type="text/javascript" src="/static/bui/js/config.js"></script>
      <script type="text/javascript">

        BUI.use(['bui/grid', 'bui/data', 'bui/form'], function (Grid, Data, Form) {
          var columns = [
                    {title: '生成信息日期', dataIndex: 'date', width: '20%'},
                    {title: '教师姓名', dataIndex: 'teacher', width: '15%'},
                    {title: '金额', dataIndex: 'pay', width: '10%'},
                    {title: '工资信息', dataIndex: 'info', width: '40%'}
                  ],
          //默认的数据
                  data = [
                    <c:forEach items="${salary}" var="r">
                    {
                      _id: '${r._id}',
                      teacher: '${r.teacher}',
                      date: '${r.date}',
                      info: '${r.info}',
                      pay: '${r.pay}'
                    },
                    </c:forEach>
                  ],
                  store = new Data.Store({
                    data: data,
                    pageSize: 10
                  }),
                  editing = new Grid.Plugins.DialogEditing({
                    contentId: 'content',
                    triggerCls: 'btn-edit',
                    editor: {
                      focusable: false,
                      success: function () {
                        var editType = editing.get('editType'),
                                edtor = this,
                                form = edtor.get("form");
                        form.valid();
                      }
                    }
                  }),
                  grid = new Grid.Grid({
                    render: '#grid',
                    columns: columns,
                    width: '100%',
//                    forceFit: true,
                    plugins: [Grid.Plugins.AutoFit],
                    store: store,
                    bbar: {
                      pagingBar: true,
                      elCls: 'image-pbar'
                    },
                    plugins: [Grid.Plugins.CheckSelection, editing],
                    tbar: {
                      items: []
                    }
                  });
          grid.render();


          function delFunction() {
            var selections = grid.getSelection();
            delItems(selections);
          }

          function delItems(items) {
            var _ids = [];
            BUI.each(items, function (item) {
              _ids.push(item._id)
            });
            if (_ids.length) {
              BUI.Message.Confirm('确认要删除吗？', function () {
                $.ajax({
                  type: 'POST',
                  url: '/salary/delSalary?_ids=' + _ids,
                  success: function (msg) {
                    if (msg == 'success') {
                      msg = "删除成功！";
                      BUI.Message.Alert(msg, function () {
                        window.location.href = '/salary/list.do';
                      }, 'success')
                    } else {
                      msg = '删除失败'
                      BUI.Message.Alert(msg, function () {
                        window.location.href = '/jsp/error/noAuthority.jsp';
                      }, 'error')
                    }
                  }
                })
              })
            }
          };
          var form = new Form.HForm({
            srcNode: '#J_Form'
          });
        });
      </script>
    </div>
  </div>
</div>
</body>
</html>
